/**
 * 上海中赢金融信息服务有限公司
 * Copyright (c) 2017-2027 Chinazyjr,Inc.All Rights Reserved.
 */
package com.sys.midware.hbase.model;

import java.util.Arrays;
import java.util.Set;

/**
 * hbaseRow <b>ClassName：</b> HbaseRow <br/>
 * <b>Description：</b> TODO <br/>
 * <b>@author：</b> mobing <br/>
 * <b>@date：</b> 2015年10月26日 下午5:24:17 <br/>
 * <b>@version: </b> <br/>
 */
public class HbaseRow {

    private byte[] row = null;

    private Set<HbaseColumn> columns = null;

    public HbaseRow() {
        this(null, null);
    }

    public HbaseRow(byte[] row) {
        this(row, null);
    }

    public HbaseRow(byte[] row, Set<HbaseColumn> columns) {
        super();
        this.row = row;
        this.columns = columns;
    }

    public void setColumns(Set<HbaseColumn> columns) {
        this.columns = columns;
    }

    public void setRow(byte[] row) {
        this.row = row;
    }

    public byte[] getRow() {
        return row;
    }
    public String getRowAsString() {
        if (row != null)
            return new String(row);
        else
            return null;
    }
    public Set<HbaseColumn> getColumns() {
        return columns;
    }
    /**
     * 获取自定义别名
     * @param  
     * @return  String
     */
    public String getQualifierValue(String cf, String qualifierName) {
        for (HbaseColumn c : columns) {
            if (cf.equalsIgnoreCase(c.getColumnFamily()) && qualifierName.equalsIgnoreCase(c.getColumn()))
                return c.getValue();
        }
        return null;
    }
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((columns == null) ? 0 : columns.hashCode());
        result = prime * result + Arrays.hashCode(row);
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        HbaseRow other = (HbaseRow) obj;
        if (columns == null) {
            if (other.columns != null)
                return false;
        } else if (!columns.equals(other.columns))
            return false;
        if (!Arrays.equals(row, other.row))
            return false;
        return true;
    }

    @Override
    public String toString() {
        return "HbaseRow [row=" + Arrays.toString(row) + ", columns=" + columns + "]";
    }

}
